package top.meeting.room.common.interceptors;


import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.plugin.activerecord.ActiveRecordException;
import top.meeting.room.common.base.BaseRender;
import top.meeting.room.common.exceptions.HandlerException;

/**
 * 我有故事，你有酒么？
 * JKhaled created by yunqisong@foxmail.com 2017/7/22
 * FOR : 异常拦截器
 */
public class ExceptionInterceptor implements Interceptor {
    @Override
    public void intercept(Invocation inv) {
        BaseRender controller = (BaseRender) inv.getController();
        try {
            inv.invoke();
        } catch (HandlerException e) {/**优先拦截我们手动抛出的异常*/
            controller.renderJsonError(e.getCode(), e.getMessage());
        } catch (ActiveRecordException e){
            e.printStackTrace();
            controller.renderJsonError("数据库操作异常");
        }
    }
}
